﻿using LightWadf.Result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LightWadf.Handler
{
    public class ResultParser
    {
        public static void Parse(object result, HttpResponse response)
        {
            if (result != null)
            {
                if (result is JsonResult)
                {
                    response.ContentType = "application/json";
                    response.Write((result as JsonResult).JsonString);
                }
                else if (result is RedirectResult)
                {
                    response.Redirect((result as RedirectResult).Url);
                }
                else if (result is HtmlResult)
                {
                    response.Write((result as HtmlResult).HtmlString);
                }
                else if(result is RazorResult)
                {
                    response.Write((result as RazorResult).HtmlString);
                }
                else if (result is FileResult)
                {
                    response.WriteFile((result as FileResult).FileName);
                }
                else response.Write(result);
            }
            else
            {
                return;
            }
        }
    }
}